package com.xy.annotaion.handler.kotlin.word

import cn.hutool.core.io.FileUtil
import com.xy.annotaion.handler.kotlin.p
import org.jsoup.Jsoup
import java.net.URLDecoder

val urls = arrayListOf(
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=381460648107446272&orgId=236869333790371840",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=373039447223873536&orgId=237283626977472512",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371686881625944064&orgId=239107342938025984",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=381820194206257152&orgId=239341250245963776",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=373145415353937920&orgId=239688572247093248",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=372040904182902784&orgId=239736682931433472",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371345214557392896&orgId=240032794628206592",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=372760974248906752&orgId=240043257814462464",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=372778518854807552&orgId=240884842747801600",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=374149322670608384&orgId=241497782819631104",
//    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=390848768234008576&orgId=241845438456672256",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371687368098058240&orgId=242200196858130432",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=372770126497058816&orgId=242210566108753920",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=372351047089000448&orgId=242318362078752768",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=374499242065793024&orgId=242567626612682752",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371687785708171264&orgId=242575719094431744",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=372049111735382016&orgId=243309767517417472",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=373507131656941568&orgId=243746813071470592",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=373507664228651008&orgId=244390141022580736",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=391572012440268800&orgId=251012814741188608",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=372773743429947392&orgId=254155178745802752",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=372694605176246272&orgId=332912816337465344",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=372759280282767360&orgId=368706514237009920",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371937205812989952&orgId=369072087508725760",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379283652841615360&orgId=371339151728455680",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379281506280673280&orgId=371345044377448448",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379218211259592704&orgId=371345440214888448",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379281394724769792&orgId=371345968168710144",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379281287908429824&orgId=371346385866862592",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379280432786313216&orgId=371373927944433664",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379202357042130944&orgId=371375341898838016",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379200516946440192&orgId=371375679880048640",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379201558069161984&orgId=371376031459192832",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379198756429238272&orgId=371376258438148096",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371688512832712704&orgId=371605595150102528",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371685026799857664&orgId=371606396744511488",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371620852652617728&orgId=371606986442682368",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371697475208876032&orgId=371607822791094272",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=379192631864594432&orgId=371608417987997696",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371617101606858752&orgId=371609153756999680",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371690331860414464&orgId=371609831535554560",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371687437861957632&orgId=371610195873771520",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371697792818352128&orgId=371610618168881152",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=371677886769049600&orgId=371610852018106368",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=389305480083410944&orgId=373045939368636416",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=383673279207706624&orgId=373122458405318656",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=382445758361374720&orgId=382440445251694592",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=383982145535479808&orgId=383677458982383616",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=386603483936894976&orgId=386294312821338112",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=386792103138340864&orgId=386789137303744512",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=387705273721860096&orgId=387700504646922240",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=389112338247847936&orgId=387941767694528512",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=388053097336582144&orgId=387947239575138304",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=388761859227652096&orgId=388407333546897408",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=389038883980750848&orgId=389037767515451392",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=390617023467270144&orgId=390242522552086528",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=390247951500054528&orgId=390245342533660672",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=390612376476192768&orgId=390607904961998848",
    "http://localhost:20009/export/org/word?planId=371324244710961152&taskId=395695962007056384&orgId=395678079721680896"
)

fun main() {

    val homePath = "c:/Users/Dell/Desktop/org";
    p(FileUtil.exist(homePath))

    val maxBytes = 1024 * 1024 * 100
    for (url in urls) {
        p(url)
        val res =
            Jsoup.connect(url)
                .ignoreContentType(true)
                .maxBodySize(maxBytes)
                .execute()
        val filenameHeader = res.header("Content-disposition");
        val filename = filenameHeader.split("=")[1];
        val path = "$homePath/" + URLDecoder.decode(filename, "UTF-8")
        p(path)
        FileUtil.writeBytes(res.bodyAsBytes(), path);

    }


}
